﻿using UnityEngine;
using System.Collections;

public class Paddle : MonoBehaviour {
    public float speed;
    public float XMin;
    public float XMax;
    public GameObject ball;
	// Use this for initialization
	void Start () {
	    
	}
	
	// Update is called once per frame
	void Update () {
        float xx = Input.GetAxisRaw("Horizontal");
        if(xx!=0)
        {
            Vector3 pos = transform.position;
            pos.x += xx*speed*Time.deltaTime;
            pos.x = Mathf.Clamp(pos.x, XMin, XMax);    //钳制
            transform.position = pos;
            if (!GM.instance.isPlaying)
            {
                Vector3 pos_of_ball = ball.transform.position;
                pos_of_ball.x += xx * speed * Time.deltaTime;
                pos_of_ball.x = Mathf.Clamp(pos_of_ball.x, XMin, XMax);    //钳制
                ball.transform.position = pos_of_ball;

            }
        }
        
    }
}
